#!/usr/bin/perl -w
print "Content-type:text/html\n";
$page 		= $ARGV[0];
$group		= $ARGV[1];
@groupsArray = split(/,/, $group);
$load = "False";

$file = '../admin/users/permissions.txt';		# Name the file
open(INFO, $file) or die("File Open Failed");		# Open the file
	
	
	
while ($_ = <INFO>)   # Read a line
{	

	# not a comment neither a white line neither white space character
	if (		     
		          /(\s*([[:alnum:]]+)\s*)\|
		    			  (.*|\s*)\|
         	       (\s*\w*\s*(,\s*\w+\s*)*\s*)\|
		       (\s*\w*\s*(,\s*\w+\s*)*\s*)\#?
		          (\s*[\x20-\x7E]*\s*\n)/x )
	{
	
		$tempPage = $1;
		$disabled = $3;	
		$allowedGroups = $4;
		$deniedGroups  = $6;
		
		#cleaning white SPace for comaprison
		$allowedGroups =~ s/^\s+//;
		$allowedGroups =~ s/\s+$//;
		$deniedGroups =~ s/^\s+//;
		$deniedGroups =~ s/\s+$//;
		$tempPage =~ s/^\s+//;
		$tempPage =~ s/\s+$//;
		
		#page found
		if ( $page =~ /$tempPage/)
		{
		
			#if disabled
			if ($disabled =~ /.[^\s]/)
			{
				#The page is disabled
				last;
					
			}
			else
			{	
						 	
				foreach $item (@groupsArray)
				{
					$item =~ s/^\s+//;
					$item =~ s/\s+$//;
					

					if( $allowedGroups =~ /$item/)
					{
						if($deniedGroups =~ /$item/ )
						{
							last;
							
						}
						else
						{
							$load = "True";
							last;
						}
					}
		
				}				
			}
			
			
			
				
		}#if for DeniedAcces to all
	
	}#if for REGEX

	
}#while

print $load;
close(INFO);			# Close the file





